package org.devio.secondlevelmenu.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import org.devio.secondlevelmenu.R;
import org.devio.secondlevelmenu.bean.VipShareFirstLebalBean;
import org.devio.secondlevelmenu.bean.VipShareSecondLeftLebalBean;
import org.devio.secondlevelmenu.bean.VipShareSecondRightLebalBean;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class LabelTwoLeftRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<VipShareSecondLeftLebalBean> mDatas = new ArrayList<>();


    private onItemClick onItemClick;

    public void setOnItemClick(onItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }

    public interface onItemClick {
        void onItemClick(VipShareSecondLeftLebalBean bean, int position);
    }

    public LabelTwoLeftRecyclerViewAdapter(Context context) {
        mContext = context;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(mContext).inflate(R.layout.level2menu_left_item_layout, parent, false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        MyViewHolder normalHolder = (MyViewHolder) holder;
        if (position < mDatas.size() && mDatas.get(position) != null) {
            normalHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemClick != null)
                        onItemClick.onItemClick(mDatas.get(position), position);
                }
            });
            normalHolder.mImg.setVisibility(View.GONE);

            normalHolder.mTV.setText(mDatas.get(position).getTxt());
            if (mDatas.get(position).isSelected) {
                normalHolder.mTV.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                if (mDatas.get(position).isChildSelected())
                    normalHolder.mImg.setVisibility(View.VISIBLE);

            } else {

                normalHolder.mTV.setTextColor(Color.parseColor("#FF3F3F3F"));

            }
        }
//        normalHolder.mImg.setImageResource(?);
//        normalHolder.mImg.setImageResource(?);

    }

    public void setData(List<VipShareSecondLeftLebalBean> mDatas) {
        this.mDatas.clear();
        this.mDatas.addAll(mDatas);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        public TextView mTV;
        public ImageView mImg;

        public MyViewHolder(View itemView) {
            super(itemView);
            mTV = itemView.findViewById(R.id.level2_left_item_tv);
            mImg = itemView.findViewById(R.id.level2_left_item_iv);

        }

    }
}

